<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE>
<html>
<head>
<meta charset=UTF-8>
<title></title>
<link rel="stylesheet" href="${webroot }css/bootstrap.min.css">
<script src="${webroot }js/jquery.min.js"></script>
<script src="${webroot }js/bootstrap.min.js"></script>
<script src="${webroot }js/web.config.js"></script>
<link rel="stylesheet" href="${webroot }css/common.css">
<link rel="stylesheet" href="${webroot }css/client.css">
</head>
<body>
	<table class="table">
    <caption>基本信息<a data-toggle="modal" data-target="#myModal">修改密码</a></caption>
    <tbody>
      <tr>
        <td>账号：</td>
        <td>${admin.adminCode }</td>
        <td>显示名：</td>
        <td>${admin.adminName }</td>
      </tr>
    </tbody>
  </table>
  
  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" 
   aria-labelledby="myModalLabel" aria-hidden="true">
   <div class="modal-dialog">
      <div class="modal-content">
         <div class="modal-header">
            <button type="button" class="close" 
               data-dismiss="modal" aria-hidden="true">
                  &times;
            </button>
            <h4 class="modal-title" id="myModalLabel">修改密码</h4>
         </div>
         <div class="modal-body">
           <div class="form-group">
             <label class="login_label">原密码：</label>
             <input class="form-control login_input" id="focusedInput" type="password" 
               placeholder="请输入原密码" name="oldPass">
           </div>
           <div class="form-group">
             <label class="login_label">新密码：</label>
             <input class="form-control login_input" id="focusedInput" type="password" 
               placeholder="请输入新密码" name="newPass">
           </div>
           <div class="form-group">
             <label class="login_label">确认新密码：</label>
             <input class="form-control login_input" id="focusedInput" type="password" 
               placeholder="请确认新密码" name="surePass">
           </div>
         </div>
         <div class="modal-footer">
         	<span id="res_msg"></span>
            <button type="button" class="btn btn-default" 
               data-dismiss="modal">关闭</button>
            <button type="button" id="change_pass" class="btn btn-primary">提交更改</button>
         </div>
      </div><!-- /.modal-content -->
  </div><!-- /.modal -->
  
  <script type="text/javascript">
 	$(document).ready(function() {
		$("#change_pass").click(function(){
			var old_pass = $("[name='oldPass']").val();
			var new_pass = $("[name='newPass']").val();
			var sure_pass = $("[name='surePass']").val();
			var res_msg = $("#res_msg");
			if(old_pass == "" || new_pass == "" || sure_pass == ""){
				res_msg.text("有必填项没有填写！");
			}else if (new_pass == sure_pass) {
				$.ajax({
					url : webRoot + "web/admin/change",
					type : "post",
					dataType : "json",
					data : {
						"oldPass" : old_pass,
						"newPass" : new_pass
					},
					success : function(data) {
						if (data.result == "success") {
							$("[name='oldPass']").val("");
							$("[name='newPass']").val("");
							$("[name='surePass']").val("");
							res_msg.text("修改成功！");
						} else {
							res_msg.text("修改失败！");
						}
					},
					error : function() {
						res_msg.text("未知错误！");
					}
				});
			} else {
				res_msg.val("两次新密码输入不一致！");
			}
		});
	});
  </script>
</body>
</html>